package com.whz.annontateddemo;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author: sinosoft
 * @Description:
 * @Date: Create in 16:19 2021/5/17
 * @Modified By:
 */
@Slf4j
public class RunTests {
    public static void main(String[] args) {
        int tests = 0;
        int passed = 0;
        try {
            Class<?> testClass = Class.forName(args[0]);
            for (Method m : testClass.getDeclaredMethods()) {
                if (m.isAnnotationPresent(Test.class)) {
                    tests++;
                    try {
                        m.invoke(null);
                        passed++;
                    } catch (IllegalAccessException wrappedExc) {
                        Throwable exc = wrappedExc.getCause();
                        log.error("{} 方法运行失败 {}", m, exc);
                    } catch (InvocationTargetException wrappedExc) {
                        Throwable exc = wrappedExc.getCause();
                        log.error("{} 方法运行失败 {}", m, exc);
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            log.error("{} 类未能找到 {}", args[0], e.getException());
        }
    }
}
